package com.ykl.demo.ctrl.convs;

import com.ykl.demo.comp.SpcRoomComp;
import com.ykl.demo.comp.conv.AbstractConverter;
import com.ykl.demo.ctrl.vm.SpcStationWithRoomsVm;
import com.ykl.demo.entity.SpcRoom;
import com.ykl.demo.entity.SpcStation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SpcStation2WithRoomVmConv extends AbstractConverter<SpcStation, SpcStationWithRoomsVm> {

    @Autowired
    private SpcRoomComp mmComp;

    @Override
    protected SpcStationWithRoomsVm conv(SpcStation s) {
        List<SpcRoom> rooms = mmComp.findByStationId(s.getStationId());
        SpcStationWithRoomsVm vm = new SpcStationWithRoomsVm();
        BeanUtils.copyProperties(s, vm);
        vm.setRooms(rooms);
        return vm;
    }

}
